#include "plook_u8s16f_binc.h"
#include "binsearch_u8s16.h"
#include "rtwtypes.h"

uint8_T plook_u8s16f_binc(int16_T u, const int16_T bp[], uint32_T maxIndex,
  real32_T *fraction)
{
  uint8_T bpIndex;
  if (u <= bp[0U]) {
    bpIndex = 0U;
    *fraction = 0.0F;
  } else if (u < bp[maxIndex]) {
    int16_T bpLeftVar;
    bpIndex = binsearch_u8s16(u, bp, maxIndex >> 1U, maxIndex);
    bpLeftVar = bp[(uint32_T)bpIndex];
    *fraction = (real32_T)(uint16_T)(u - bpLeftVar) / (real32_T)(uint16_T)
      (bp[bpIndex + 1U] - bpLeftVar);
  } else {
    bpIndex = (uint8_T)(maxIndex - 1U);
    *fraction = 1.0F;
  }

  return bpIndex;
}
